package org.blog.model;

import org.blog.service.util.ParamValidate;

public class ModelPassport extends BaseModel implements ValidateModel {

	// private String username;// 5--20包括起始
	private String pwd;// 50 真实密码长度为6--20
	private String salt;// 32
	private String email;// 32
	private Integer role;// 10+：用户有效，20+：可留言，30+：可发表文章，100+：管理员
	private Long createTime;// 13

	// public String getUsername() {
	// return username;
	// }
	//
	// public void setUsername(String username) {
	// this.username = username;
	// }

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Integer getRole() {
		return role;
	}

	public void setRole(Integer role) {
		this.role = role;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	@Override
	public boolean validate(ActionType type) {
		if (ActionType.ADD.equals(type)) {
			if (!ParamValidate.isEmail(getEmail())
					|| !ParamValidate.isPassword(getPwd())
					|| !ParamValidate.isUserName(getUsername())
					|| !ParamValidate.isUserNameLength(getUsername())) {
				return false;
			}
		} else if (ActionType.AUTH.equals(type)) {
			if (ParamValidate.isUserName(getUsername())
					&& ParamValidate.isUserNameLength(getUsername())
					&& ParamValidate.isPassword(getPwd())) {
				return false;
			}
		} else if (ActionType.MODIFY_EMAIL.equals(type)) {
			if (!ParamValidate.isEmail(getEmail())) {
				return false;
			}
		} else if (ActionType.MODIFY_PWD.equals(type)) {
			if (!ParamValidate.isPassword(getPwd())) {
				return false;
			}
		}

		return true;
	}
}
